package com.frejoys.app.controller;


import com.frejoys.common.aop.Authority;
import com.frejoys.common.aop.Authorization;
import com.frejoys.common.constant.CommonConstant;
import com.frejoys.common.dto.app.CategoryPidDto;
import com.frejoys.common.dto.app.CategorySiteDto;
import com.frejoys.common.response.Result;
import com.frejoys.common.vo.app.CategoryListVo;
import com.frejoys.common.vo.app.CategorySonListVo;
import com.frejoys.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "品类", description = "品类")
@RestController
@RequiredArgsConstructor
@RequestMapping(CommonConstant.routePrefixApp)
@Authorization(Authority.Private)
public class CategoryController {

    private final CategoryService categoryService;

    @Authorization(Authority.Protected)
    @Operation(summary = "首页菜单品类列表 大类")
    @PostMapping("/category/listInfo")
    public Result<List<CategoryListVo>> listInfo(@RequestBody @Validated CategorySiteDto dto) {
        return Result.success(categoryService.onCategory(dto,categoryService.listInfo()));
    }

    @Authorization(Authority.Protected)
    @Operation(summary = "根据品类id查询子集品类 包含父级本身品类")
    @PostMapping("/category/categoryListInfo")
    public Result<List<CategoryListVo>> categoryListInfo(@RequestBody @Validated CategoryPidDto dto) {
        return Result.success(categoryService.categoryListInfo(dto,categoryService.listInfo()));
    }

    @Authorization(Authority.Protected)
    @Operation(summary = "根据品类id查询子集品类")
    @PostMapping("/category/sonListInfo")
    public Result<List<CategoryListVo>> sonListInfo(@RequestBody @Validated CategoryPidDto dto) {
        return Result.success(categoryService.sonListInfo(dto,categoryService.listInfo()));
    }


    @Authorization(Authority.Protected)
    @Operation(summary = "全部类型 树型结构")
    @PostMapping("/category/categoryAndSonList")
    public Result<List<CategorySonListVo>> categoryAndSonList(@RequestBody @Validated CategorySiteDto dto){
        return Result.success(categoryService.categoryAndSon(dto,categoryService.listInfo()));
    }

    @Authorization(Authority.Protected)
    @Operation(summary = "全部分类")
    @PostMapping("/category/categoryAll")
    public Result<List<CategoryListVo>> categoryAll(){
        return Result.success(categoryService.categoryAll(categoryService.listInfo()));
    }


}
